package com.catazy.mvvmlib.ext.glide

import android.view.RoundedCorner
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.Glide.RequestOptionsFactory
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions

/**
 * 作者: Tao
 * 日期: 2023/12/25
 * 时间: 15:36
 * 描述: Glide 拓展类
 */

/**
 * 加载资源Id图片到ImageView
 * @param resId 资源Id 桥梁
 * @param isRadius 是否圆角 true是 false否 默认false
 */
fun ImageView.setImage(resId: Int, isRadius: Boolean = false) {
    val options = RequestOptions.bitmapTransform(RoundedCorners(20))
    var builder = Glide.with(context).load(resId)
    if (isRadius) {
        builder = builder.apply(options)
    }
    builder.into(this)
}

/**
 * 加载网络图片到ImageView
 * @param url 图片地址
 * @param isRadius 是否圆角 true是 false否 默认false
 */
fun ImageView.setImage(url: String, isRadius: Boolean = false) {
    val options = RequestOptions.bitmapTransform(RoundedCorners(20))
    var builder = Glide.with(context).load(url)
    if (isRadius) {
        builder = builder.apply(options)
    }
    builder.into(this)
}